package com.jmye.mybatis.mapper;

import com.jmye.mybatis.entity.Order;
import com.jmye.mybatis.entity.User;
import jdk.nashorn.internal.objects.annotations.Setter;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description
 * @Date 2024/11/26 下午9:11
 * @Author jmye
 */
public interface OrderMapper {
    @Select("select * from orders")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "order_time", property = "orderTime"),
            @Result(column = "total", property = "total"),
            @Result(column = "uid", property = "user", javaType = User.class,
                    one = @One(select = "com.jmye.mybatis.mapper.UserMapper.findById")
            )
    })
    List<Order> findAll();

    @Select("select * from orders where uid = #{uid}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "order_time", property = "orderTime"),
            @Result(column = "total", property = "total"),
    })
    List<Order> findById(Integer uid);
}
